﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace NeonMika.EightTracks
{
    public class Review
    {
        //TODO: Generate class members

        /*
        <review>
      <mix-id>14</mix-id>
      <created-at>2011-01-22T01:21:15Z</created-at>
      <user-id>147093</user-id>
      <body>I was so looking for a mix like this, its hard to find around here &lt;3</body>
      <id>195411</id>
      <body-html>&lt;p&gt;I was so looking for a mix like this, its hard to find around here &amp;lt;3&lt;/p&gt;</body-html>
    </review>*/

        private int mix_id;

        public int MixId
        {
            get { return mix_id; }
            set { mix_id = value; }
        }
        private DateTime created_at;

        public DateTime CreatedAt
        {
            get { return created_at; }
            set { created_at = value; }
        }
        private int user_id;

        public int UserId
        {
            get { return user_id; }
            set { user_id = value; }
        }
        private string body;

        public string Body
        {
            get { return body; }
            set { body = value; }
        }
        private int id;

        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        private string body_html;

        public string BodyHtml
        {
            get { return body_html; }
            set { body_html = value; }
        }

        public Review(XElement xml)
        {
            string element = "body";
            this.Body = xml.TryGetStringElement(element);

            element = "body-html";
            this.BodyHtml = xml.TryGetStringElement(element);

            element = "created-at";
            if (xml.Element(element) != null && xml.Element(element).Attribute("nil") == null)
            {
                string[] datetime = xml.Element(element).Value.ToString().Split('T');
                string[] date = datetime[0].Split('-');
                string[] time = datetime[1].Split(':');
                CreatedAt = new DateTime(Int32.Parse(date[0]), Int32.Parse(date[1]), Int32.Parse(date[2]), Int32.Parse(time[0]), Int32.Parse(time[1]), Int32.Parse(time[2].Remove(time[2].Length - 1)));
            }

            element = "id";
            this.Id = xml.TryGetIntElement(element);

            element = "mix-id";
            this.MixId = xml.TryGetIntElement(element);

            element = "user-id";
            this.UserId = xml.TryGetIntElement(element);
        }
    }
}
